﻿using System;

namespace QuickTest.Core.TestRunner
{
    public enum ResultState
    {
        Success,
        Failure,
        NotRun
    }

    /// <summary>
    /// The TestResult class represents the result of a completed test.
    /// </summary>
    [Serializable]
    public class TestResult
    {
        /// <summary>
        /// Gets the result of the test.
        /// </summary>
        public ResultState ResultState { get; private set; }

        /// <summary>
        /// Determines if the test succeeded.
        /// </summary>
        public bool IsSuccess
        {
            get { return ResultState == ResultState.Success; }
        }

        /// <summary>
        /// Determines if the test failed.
        /// </summary>
        public bool IsFailure
        {
            get { return ResultState == ResultState.Failure; }
        }

        /// <summary>
        /// Determines if the test was executed.
        /// </summary>
        public bool Executed
        {
            get { return ResultState != ResultState.NotRun; }
        }

        /// <summary>
        /// Gets the name of the test.
        /// </summary>
        public string TestName { get; private set; }

        public TestResult(string testName, ResultState resultState)
        {
            TestName = testName;
            ResultState = resultState;
        }

        /// <summary>
        /// Gets a string representation of a test result.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string result = String.Empty;
            switch (ResultState)
            {
                case ResultState.Failure:
                    result = "failed";
                    break;
                case ResultState.NotRun:
                    result = "not executed";
                    break;
                default:
                    break;
            }

            return String.Format("{0}... {1}", TestName, result);
        }
    }
}